set more off

use "dataset_tw", clear

forvalues i = 0(100)8000000 {
	local log`i' = log(`i' + 1)
}

#delimit;

local X 
	city_pop 
	percent_black
	median_income 
	pres_2008 
	taxes_capita 
	perc_atlarge2 
	partisan_elections2 
	initiative2 
	term_limits2
	;

#delimit cr

su `X'

destring `X', replace ignore("NA")

foreach x in `X' {

	su `x' if city == "Memphis"
	local memphis = r(mean)
	su `x' if city == "Nashville-Davidson County"
	local nashville = r(mean)

	local myscale
	
	#delimit;
	if "`x'" == "city_pop" local myscale 
			`log20000' "20k"
			`log50000' "50k"
			`log200000' "200k"
			`log2000000' "2m"
			`log8000000' "8m"
			;
	#delimit cr
	
	
	#delimit;
	if "`x'" == "taxes_capita" local myscale 
			`log100' "100"
			`log300' "300"
			`log1000' "1,000"
			`log8000' "8,000"
			;
	#delimit cr
	
	local mytextmemphis
	local mytextnashville

	#delimit;
	if "`x'" == "city_pop" local mytextnashville
			text(0.7 `log180000' "Nashville", col(gray))
			;
	if "`x'" == "city_pop" local mytextmemphis
			text(0.7 `log1700000' "Memphis", col(black))
			;
	#delimit cr

	local templabel : var label `x'
	
	#delimit;
	
	gr tw 
		(kdensity `x', col(black))
		,	
			xline(`nashville', lcol(gs10) lwid(vthick)) 
			xline(`memphis', lcol(black) lpat(dash))
			title(`templabel')		
			nodraw
			xlab(`myscale')
			yscale(off)
			name(g`x', replace)
			plotregion(style(none))
			ylab(, angle(horiz))
			ytitle("")
			xtitle("")
			`mytextmemphis'
			`mytextnashville'
			;
	
	#delimit cr
	
	local mygraphs `mygraphs' g`x'
	
}

gr combine `mygraphs'

gr export "figure A3.eps", replace
shell epstopdf "figure A3.eps"
